<template>
  <el-dialog
    :title="!dataForm.remarkId ? '新增' : '修改'"
    :close-on-click-modal="false"
    :visible.sync="visible">
    <el-form :model="dataForm" :rules="dataRule" ref="dataForm" @keyup.enter.native="dataFormSubmit()" label-width="80px">
    <el-form-item label="用户id" prop="userId">
      <el-input v-model="dataForm.userId" placeholder="用户id"></el-input>
    </el-form-item>
    <el-form-item label="楼盘id" prop="housesId">
      <el-input v-model="dataForm.housesId" placeholder="楼盘id"></el-input>
    </el-form-item>
    <el-form-item label="点评内容" prop="remarkContent">
      <el-input v-model="dataForm.remarkContent" placeholder="点评内容"></el-input>
    </el-form-item>
    <el-form-item label="点评时间" prop="remarkTime">
      <el-input v-model="dataForm.remarkTime" placeholder="点评时间"></el-input>
    </el-form-item>
    <el-form-item label="点评状态" prop="remarkStatic">
      <el-input v-model="dataForm.remarkStatic" placeholder="点评状态"></el-input>
    </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="visible = false">取消</el-button>
      <el-button type="primary" @click="dataFormSubmit()">确定</el-button>
    </span>
  </el-dialog>
</template>

<script>
  export default {
    data () {
      return {
        visible: false,
        dataForm: {
          remarkId: 0,
          userId: '',
          housesId: '',
          remarkContent: '',
          remarkTime: '',
          remarkStatic: ''
        },
        dataRule: {
          userId: [
            { required: true, message: '用户id不能为空', trigger: 'blur' }
          ],
          housesId: [
            { required: true, message: '楼盘id不能为空', trigger: 'blur' }
          ],
          remarkContent: [
            { required: true, message: '点评内容不能为空', trigger: 'blur' }
          ],
          remarkTime: [
            { required: true, message: '点评时间不能为空', trigger: 'blur' }
          ],
          remarkStatic: [
            { required: true, message: '点评状态不能为空', trigger: 'blur' }
          ]
        }
      }
    },
    methods: {
      init (id) {
        this.dataForm.remarkId = id || 0
        this.visible = true
        this.$nextTick(() => {
          this.$refs['dataForm'].resetFields()
          if (this.dataForm.remarkId) {
            this.$http({
              url: this.$http.adornUrl(`/backstage/userhousesremark/info/${this.dataForm.remarkId}`),
              method: 'get',
              params: this.$http.adornParams()
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.dataForm.userId = data.userHousesRemark.userId
                this.dataForm.housesId = data.userHousesRemark.housesId
                this.dataForm.remarkContent = data.userHousesRemark.remarkContent
                this.dataForm.remarkTime = data.userHousesRemark.remarkTime
                this.dataForm.remarkStatic = data.userHousesRemark.remarkStatic
              }
            })
          }
        })
      },
      // 表单提交
      dataFormSubmit () {
        this.$refs['dataForm'].validate((valid) => {
          if (valid) {
            this.$http({
              url: this.$http.adornUrl(`/backstage/userhousesremark/${!this.dataForm.remarkId ? 'save' : 'update'}`),
              method: 'post',
              data: this.$http.adornData({
                'remarkId': this.dataForm.remarkId || undefined,
                'userId': this.dataForm.userId,
                'housesId': this.dataForm.housesId,
                'remarkContent': this.dataForm.remarkContent,
                'remarkTime': this.dataForm.remarkTime,
                'remarkStatic': this.dataForm.remarkStatic
              })
            }).then(({data}) => {
              if (data && data.code === 0) {
                this.$message({
                  message: '操作成功',
                  type: 'success',
                  duration: 1500,
                  onClose: () => {
                    this.visible = false
                    this.$emit('refreshDataList')
                  }
                })
              } else {
                this.$message.error(data.msg)
              }
            })
          }
        })
      }
    }
  }
</script>
